#include "../../include/Core/Application.h"
#include "../../include/Logic/Player.h"
bool Application::Init(Renderer*& renderer,Input*& input) {
    renderer = RendererFactory::CreateRenderer("easyx");
    input = InputFactory::CreateInput("easyx");

    renderer->init(renderer);
    input->init(input);

    return true;
}
Player* player = new Player(1,true,10,10,3,10);//生成玩家;
void Application::Run() {
    //主循环
    if (Application::Init(renderer, input)) {
        while (running) {
            time1 = ::GetTickCount();
            //读取操作
            input->handleEvents(player);
            //end读取操作
            //处理数据

            //end处理数据
            //绘制画面
            renderer->draw(player);
            //end绘制画面

            time2 = ::GetTickCount();
            //test
            //printf("%d\n", time2 - time1);
            //endtest
            renderer->flush();
            delta_time = (time2 - time1);//60帧
            if (delta_time < 1000 / 60) {
                Sleep(1000 / 60 - delta_time);
            }
        }
        //释放资源
        Shutdown();
    }
}
void Application::Shutdown() {
    running = false;
    delete renderer;
    delete input;
    //delete player;
}

